﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMain.Master" Inherits="System.Web.Mvc.ViewPage<TvGuide.UI.Models.ProgramData>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Model.MianTitle %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
   
        <div class="Home-page_Channel_Div" >

            <% foreach (var ch in Model.ChList) 
               {  
   
            %>
            <div class="Home-page_Channel_Div_Element_Container">
            <% 
                bool isselected = (ViewData["selch"].ToString() == ch.ID.ToString() && Convert.ToBoolean(ViewData["Runing"]) == false);
                 %>
            
                <div id="<%: ch.ID %>" alt ="<%: Model.Lng %>" style='background-color:<%=isselected?"#E0E0E0":"" %>' class="Home-page_Channel_Div_Element" title=" <%: ch.DispName %>" url="<%: Url.Action("GetProg","Home",new {ch=ch.ID,id=(int)DateTime.Now.AddHours(12).DayOfWeek,lng=Int32.Parse(ViewData["lng"].ToString())})   %>">
                   
                    <img class="Home-page_Channel_Div_Element_Img" alt="<%: ch.Name %>" src="<%: ch.ImgUrl %>" />
                </div>
            </div>
            <%} %>
        </div>
        <div class="Home-page_Prog_Div">
            <div class="Home-page_Prog_Div_HeadMenu" >
            <%  int i = 1; 
                string selected = "selected_day";  
                bool isDaysel; 
            %>
                <% foreach (string ss in Model.WeekDay)
                   {
                       isDaysel = false;
                       if (i == Convert.ToInt32(ViewData["selday"].ToString()) && Convert.ToBoolean(ViewData["Runing"]) == false)
                       {
                           selected = "selected_day";
                           isDaysel = true;
                       }
                       else
                       {
                           selected = "not_selected_day";
                       }
                %>
                       
                <div id="<%:selected %>"  class="Home-page_Prog_Div_HeadMenu_Buttons" url="<%: Url.Action("GetProg","Home",new {ch=Int32.Parse(ViewData["selch"].ToString()),id=i,lng=Int32.Parse(ViewData["lng"].ToString())})   %>">
                    <%: ss%></div>
                <%i++;
           } %>
           
            </div>
            <div style="clear" id="catchooser"><% Html.RenderPartial("CategoryWidget"); %></div>
            <div class="Home-page_Prog_Div_ProgramsAnnouncements">
               
                <div class="Home-Home-page_NowRuning_Div">
                    <div id="NowRun" class="NowRun Home-page_Prog_Div_HeadMenu_Buttons" url="<%: Url.Action("GetRuning","Home",new {id=0,lng=Int32.Parse(ViewData["lng"].ToString())})   %>">
                        <%= Model.OnAir %>
                    </div>
                    <div class="Home-Home-page_NowRuning_Div_Input">
                        <input type="text"  id="amount" readonly="readonly" name="<%: DateTime.Now.AddHours(12).Hour %>" value="<%: Model.OnAirVal %>" style="border: 0;
                            color: #094B90; font-weight: bold;" />
                        <div id="slider">
                        </div>
                    </div>
                </div>

                <div class="Home-page_Prog_Div_Programs">


                <%= Model.ProgsListHtml  %>
                </div>
                <div class="Home-page_Prog_Div_Announcements">
                </div>
            </div>
            <div id="LoadingDiv" ><br/><br/>
                <img alt="" id="Load" src="/Content/loading.gif" />
            </div>
        </div>
    </div>
    
    <script type="text/javascript">

  ///////////Start slider///////////     

        $(function () {
            $("#slider").slider({
                value: $("#amount").attr("name")<8? 47-2*$("#amount").attr("name"): 2*($("#amount").attr("name"))-16,
                min: 0,
                max: 47,
                step: 1,
                slide: function (event, ui) {
                 $("#amount").val(formatTime(ui.value));
                },
                
                stop: function(event, ui) {

                    $("div.Home-page_Prog_Div_Programs").html("");
                  $.ajax(
                        {
                            url: "/Home/GetRuning/" + ui.value + "/1/1",
                            type: "post",
                            data: $(this).serialize(),
                            success: function (PrData) {
                                $("div.Home-page_Prog_Div_Programs").html(PrData.ProgsListHtml);
                                ProgCatChbxChecker();

                            }
                        });

                 }

                });
              //  var vall = $("#slider").slider("value");
                $("#amount").val($("#amount").attr("name")+":"+"00");
            
        });

/////////////////////////////FormatTIme function//////////////
function formatTime(val)
{
   var vall = 8+Math.floor(val / 2);
                if(vall>24)
                vall = vall-24;


                var retstr;

                if (vall < 10)
                    retstr = "0" + vall.toString();
                else if (vall == 24)
                    retstr = "00";
                else
                    retstr = vall.toString();

                if (30 * (val % 2) == 0)
                    retstr = retstr + ":00";
                else
                    retstr = retstr + ":"+(30*(val % 2)).toString();

                return retstr;
}
////////////////////////// FormatVal function////////////////////
function formatVal(val)
{
    var vall;
    if (val < 8)
        vall = 46 - 2 * vall;
    else
        vall = 2 * vall;
    return vall;
}

///////////////////////////////////vvvv//////////////////////

function ResetSlider() {

    $(function () {
        $("#slider").slider({
            value: $("#amount").attr("name") < 8 ? 47 - 2 * $("#amount").attr("name") : 2 * ($("#amount").attr("name")) - 16,
            min: 0,
            max: 47,
            step: 1,
            slide: function (event, ui) {
                $("#amount").val(formatTime(ui.value));
            },

            stop: function (event, ui) {

                $("div.Home-page_Prog_Div_Programs").html("");
                $.ajax(
                        {
                            url: "/Home/GetRuning/" + ui.value + "/1/1",
                            type: "post",
                            data: $(this).serialize(),
                            success: function (PrData) {
                                $("div.Home-page_Prog_Div_Programs").html(PrData.ProgsListHtml);
                                ProgCatChbxChecker();

                            }
                        });

            }

        });
        //  var vall = $("#slider").slider("value");
        $("#amount").val($("#amount").attr("name") + ":" + "00");

    });
}

//////// Div Loading/////////////////////////////////////

        $('#LoadingDiv')
                            .hide()  // hide it initially
                            .ajaxStart(function () {
                                $(this).show();
                            })

                            .ajaxStop(function () {
                                $(this).hide();
                                $('div.Home-page_Prog_Div_Programs').fadeIn(100, function () {
                                    // Animation complete
                                });
                            });

/////////////////////Program buttons click ///////////////

                            $("div.Home-page_Channel_Div_Element").click(
            function () {
                
                $("div.Home-page_Prog_Div_Programs").html("");
                $("#amount").hide();
                $("#slider").hide();

                //    $("div.Home-page_Prog_Div_HeadMenu_Buttons").each(function (i, obj) {
                //        $(obj).css("color", "");
                //    });
                $("div.Home-page_Channel_Div_Element").each(function (i, obj) {
                    $(obj).css("background-color", "");
                });
                $(this).css("background-color", "#E0E0E0");
                var dayOfWeek = 0;
                var urlarr = $(this).attr("url").split("/");
                $("div.Home-page_Prog_Div_HeadMenu_Buttons").each(function (i, obj) {

                    if ($(obj).attr("id").indexOf("NowRun") != -1)
                        $(obj).css("color", "");

                    if ($(obj).attr("id") == "selected_day") {
                        dayOfWeek = i + 1;
                    }
                    else {
                        $(obj).css("color", "");
                    }

                });
                if (dayOfWeek == 0) {
                    dayOfWeek = 1;
                    $("div.Home-page_Prog_Div_HeadMenu_Buttons").each(function (i, obj) {
                        if (i == 0)
                            $(obj).attr("id") == "selected_day"
                    });
                }

                var lng = $(this).attr("alt");
                var url = "/Home/GetProg/" + $(this).attr("id") + "/" + dayOfWeek + "/" + lng;


                $.ajax(
                {
                    url: url,
                    type: "post",
                    data: $(this).serialize(),
                    success: function (PrData) {

                        $("div.Home-page_Prog_Div_HeadMenu_Buttons").each(function (i, obj) {
                            var url1 = "/Home/GetProg/" + PrData.ChID.toString() + "/" + (i + 1).toString() + "/" + lng;

                            if ($(obj).attr("id").indexOf("NowRun") == -1)
                                $(obj).attr("url", url1);



                            if ($(obj).attr("id").indexOf("NowRun") == -1) {
                                if (i + 1 != dayOfWeek)
                                    $(obj).attr("id", "not_selected_day");
                                else {
                                    $(obj).attr("id", "selected_day");
                                }
                            }
                        });
                        $("div.Home-page_Prog_Div_Programs").html(PrData.ProgsListHtml);
                        ProgCatChbxChecker();

                    }
                });


            });

////////////////////////////////Week days buttons click///////////////////

            $("div.Home-page_Prog_Div_HeadMenu_Buttons").click(
                    function () {
                        $("div.Home-page_Prog_Div_Programs").html("");

                        if ($(this).attr("id").indexOf("NowRun") != -1) {
                            $("#amount").show();
                            $("#slider").show();
                        }
                        else {
                            $("#amount").hide();
                            $("#slider").hide();
                        }

                        $("div.Home-page_Prog_Div_HeadMenu_Buttons").each(function (i, obj) {

                            if ($(obj).attr("id").indexOf("NowRun") == -1)
                                $(obj).attr("id", "not_selected_day");
                            else
                                $(obj).attr("id", "not_NowRun");


                        });

                        var Selprog = 0;

                        if ($(this).attr("id").indexOf("NowRun") == -1) {
                            $(this).attr("id", "selected_day");
                            $("div.Home-page_Channel_Div_Element").each(function (i, obj) {

                                if ($(obj).css("background-color") == "#E0E0E0")
                                    Selprog = 1;
                            });

                            $("div.Home-page_Channel_Div_Element").each(function (i, obj) {

                                if (i == 0 && Selprog == 0)
                                    $(obj).css("background-color", "#E0E0E0");

                            });

                        }
                        else {
                            $(this).attr("id", "NowRun");
                            $("div.Home-page_Channel_Div_Element").each(function (i, obj) {
                                $(obj).css("background-color", "");
                            });

                            //    $("#slider").slider("value") = $("#amount").attr("name") < 8 ? 47 - 2 * $("#amount").attr("name") : 2 * ($("#amount").attr("name")) - 16;
                            ResetSlider();
                        }
                        //window.alert($(this).attr("url"));
                        $.ajax(
                        {

                            url: $(this).attr("url"),
                            type: "post",
                            data: $(this).serialize(),
                            success: function (PrData) {
                                $("div.Home-page_Prog_Div_Programs").html(PrData.ProgsListHtml);
                                ProgCatChbxChecker();

                            }
                        });
                        return false;

                    });

                

    </script>
</asp:Content>
